package com.haohe.wx.controller;

import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dom4j.Element;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.haohe.wx.util.PropertiesReadUtil;
import com.haohe.wx.util.WXUtil;
import com.haohe.wx.util.WebDataReceive;

@Controller
@RequestMapping(value="/testController")
public class TestController {

	@ResponseBody
	@RequestMapping(value="/getList")
	public ModelAndView getList(HttpServletResponse response, HttpServletRequest request) throws FileNotFoundException{
		   ModelAndView view = new ModelAndView();
     	   try {
					String appId = PropertiesReadUtil.INSTANCE.getProperty("corpid");
					String access_token_url = PropertiesReadUtil.INSTANCE.getProperty("oauth2_get_code");
		            String url =String.format(access_token_url, appId,"/testController/getCode");
		    		String responseJson = WebDataReceive.HTTPS.receiveData(url, null);
		    		Element element = WXUtil.parseStr2Ele(responseJson);
					String event = ((Element) element.selectObject("code")).getTextTrim();
		    		System.out.println(event);
			} catch (Exception e) {
				e.printStackTrace();
			}
		return view;
	}
	
	@RequestMapping(value="findById")
	public Map<String,Object> findById(){
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		jsonMap.put("Key", "Value");
		return jsonMap;
	}
	
	
}
